1782B - Going to the Cinema - CodeForces Solution


brute force greedy sortings *1000

Please click on ads to support us..

C++ Code:

#pragma warning(disable:4996)

#include <algorithm>
#include <iostream>
#include <cstring>
#include <random>
#include <vector>
#include <cstdio>
#include <queue>
#include <cmath>
#include <map>

using std::cin;
using std::cout;
using std::endl;

constexpr long long mod = 998244353;

void clear();

void init();

void solve();

int main()
{
    std::ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    init();
    int T = 0;
    for (cin >> T; T; --T)
    {
        clear();
        solve();
    }
    return 0;
}

void init()
{

}

void clear()
{

}

void solve()
{
    int n = 0;
    cin >> n;
    std::vector <int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    std::sort(a.begin(), a.end());
    int ans = a[0] != 0;

    for (int k = 0; k < n - 1; ++k) // a[0] .. a[k] , totally k + 1 people go to the cinema
    {
        ans += a[k + 1] > k + 1 && a[k] <= k;
    }

    cout << ans + (a[n - 1] < n) << endl;
}


Comments

Submit
0 Comments
More Questions

659E - New Reform
1385B - Restore the Permutation by Merger
706A - Beru-taxi
686A - Free Ice Cream
1358D - The Best Vacation
1620B - Triangles on a Rectangle
999C - Alphabetic Removals
1634C - OKEA
1368C - Even Picture
1505F - Math
1473A - Replacing Elements
959A - Mahmoud and Ehab and the even-odd game
78B - Easter Eggs
1455B - Jumps
1225C - p-binary
1525D - Armchairs
1257A - Two Rival Students
1415A - Prison Break
1271A - Suits
259B - Little Elephant and Magic Square
1389A - LCM Problem
778A - String Game
1382A - Common Subsequence
1512D - Corrupted Array
667B - Coat of Anticubism
284B - Cows and Poker Game
1666D - Deletive Editing
1433D - Districts Connection
2B - The least round way
1324A - Yet Another Tetris Problem